package com.ruoyi.yljf.controller.AppController;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yljf.domain.Certificates;
import com.ruoyi.yljf.domain.vo.CertificatesVO;
import com.ruoyi.yljf.service.ICertificatesService;
import com.ruoyi.yljf.util.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 证书记录Controller
 * 
 * @author metaee
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/api/certificates")
public class ApiCertificatesController extends BaseController {
    @Autowired
    private ICertificatesService certificatesService;
    @Resource
    private CommonUtils commonUtils;

    /**
     * 查询证书记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest req) {
        Certificates certificates = new Certificates();
        certificates.setUserId(getUserId());
        startPage();
        List<Certificates> list = certificatesService.selectCertificatesList(certificates);
        List<CertificatesVO> vos = BeanUtil.copyToList(list, CertificatesVO.class);
        return getDataTableInfo(vos,list);
    }

    /**
     * 查询证书详情
     */
    @GetMapping("/certificateInfo/{id}")
    public AjaxResult list(@PathVariable("id") Long courseId) {
        Certificates certificates = new Certificates();
        certificates.setUserId(getUserId());
        certificates.setTargetId(courseId);
        startPage();
        List<Certificates> list = certificatesService.selectCertificatesList(certificates);
        List<CertificatesVO> vos = BeanUtil.copyToList(list, CertificatesVO.class);
        return success(vos);
    }

    /**
     * 新增证书记录
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Certificates certificates) {
        return toAjax(certificatesService.save(certificates));
    }
}
